import { apiSystemMange } from 'js/api'

export default {
  state: {
    roleList: [],
    par: {
      accessToken: '',
      threeMenuCode: '',
      currentPage: 1,
      showCount: 999,
      type: ''
    }
  },
  getters: {
    roleList: state => state.roleList
  },
  actions: {
    /**
     * 获取角色列表
     */
    fetchRole({ state }, role) {
      state.par.accessToken = role.token
      state.par.threeMenuCode = role.threeMenuCode

      apiSystemMange.getRoleLis(state.par).then(data => {
        const list = data.data || {}
        if (list && list.length == 0) return
        state.roleList = list.recordList.map(role => {
          return {
            value: role.id,
            label: role.roleName,
            level: role.level
          }
        })
        state.roleList.unshift({value: '', label: '请选择'})
      })
    }
  }
}